/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lintulaskenta.tipuapiValidointi;

import lintulaskenta.tipuapiValidointi.Document.Node;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
 *
 * @author jukkapajunen
 */
/**
 * Container holding response to TipuAPIClient request. Provides fast access to units of the resource by their ID.
 * @see Node
 */
public class TipuApiResource implements Iterable<Node> {

	private final Map<String, Node> units = new LinkedHashMap<String, Node>();

	public Collection<Node> getAll() {
		return this.units.values();
	}

	public Node getById(String id) {
		return this.units.get(id);
	}

	public TipuApiResource add(Node unit) {
		this.units.put(unit.getNode("id").getContents(), unit);
		return this;
	}

	public boolean containsUnitById(String id) {
		return this.units.containsKey(id);
	}

	public int size() {
		return this.units.size();
	}

	@Override
	public Iterator<Node> iterator() {
		return this.units.values().iterator();
	}


}
